package com.heima.behavior.listener;


import com.alibaba.fastjson.JSON;
import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.service.IApFollowBehaviorService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class UserFollowListener {

    @Autowired
    private IApFollowBehaviorService followBehaviorService;

    @KafkaListener(topics = "${topic.followBehaviorTopic}")
    public void upOrDown(ConsumerRecord<String,String> record){
        if(record!=null&&record.value()!=null){
            FollowBehaviorDto followBehaviorDto = JSON.parseObject(record.value(), FollowBehaviorDto.class);
            followBehaviorService.saveFollowBehavior(followBehaviorDto);
        }
    }

}
